package cc.mrbird.febs.buss.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCUtil {
    public static void test() {
        String RL = "jdbc:microsoft:sqlserver://47.95.200.213:1433;DatabaseName=dbQueueNet";
        String user ="wind";//这里替换成你自已的数据库用户名
        String password = "sqq8221620";//这里替换成你自已的数据库用户密码
        String sqlStr = "select * from Bus_table";

        try{    //这里的异常处理语句是必需的.否则不能通过编译!
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
            System.out.println( "类实例化成功!" );
            Connection con = DriverManager.getConnection(RL,user,password);
            System.out.println( "创建连接对像成功!" );

            Statement st = con.createStatement();
            System.out.println( "创建Statement成功!" );

            ResultSet rs = st.executeQuery( sqlStr );
            System.out.println( "操作数据表成功!" );
            System.out.println( "----------------!" );

            while(rs.next())
            {
                System.out.print(rs.getInt("Bus_id") + "    ");
                System.out.print(rs.getString("BusLine_name") + "    ");
                System.out.print(rs.getString("Bus_start_end") + "    ");
                System.out.print(rs.getByte("Bus_type") + "    ");
                System.out.print(rs.getString("BusLine_type")+"   ");
                System.out.print(rs.getByte("BusTik_type")+"");
                System.out.print(rs.getString("Bus_company")+"   ");
                System.out.print(rs.getString("BusLine_stops")+"");
                System.out.println(rs.getString("Bus_remark"));
            }
            rs.close();
            st.close();
            con.close();
        }
        catch(Exception err){
            err.printStackTrace(System.out);
        }
    }
}
